﻿module Sustainalytics.Events.Admin {

    import Common = Sustainalytics.Common;
    import CommonAdmin = Sustainalytics.Common.Admin;

    export class EventsTypesService implements IEventsTypesService {

        private items: EventType[];
        private $q: ng.IQService;

        constructor($q: ng.IQService) {

            this.$q = $q;

            // create items
            this.items =
            [
                { id: 1, name: 'Not Sponsored' },
                { id: 2, name: 'Sponsored' },
            ];
        }

        // get event type by ID
        public getEventType(id: number): ng.IPromise<EventType> {
            var def: ng.IDeferred<EventType> = this.$q.defer();

            var item: EventType = null;
            $(this.items).each(function () {
                if (this.id == id) {
                    item = this;
                    return false;
                }
            });

            def.resolve(item);

            return def.promise;
        }

        // get events types
        public getEventsTypes(): ng.IPromise<EventType[]> {
            var def: ng.IDeferred<EventType[]> = this.$q.defer();
            def.resolve(this.items);
            return def.promise;
        }
    }


    // register service with Events Angular module
    var mod = angular.module(eventsAdminModuleName);
    
    mod.service('EventsTypesService',
        ['$q', EventsTypesService]);
} 